package com.jxwifi.cloud.quickcleanserver.popwindow;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.idroid.utils.NoDoubleClickListener;
import com.jxwifi.cloud.quickcleanserver.R;
import com.jxwifi.cloud.quickcleanserver.adapter.RecordAdapter;
import com.jxwifi.cloud.quickcleanserver.bean.WithdraApplyBean;
import com.popwindow.BasicPopmodule;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/5/15.
 */

public class PopRecordModule extends BasicPopmodule {

    private Context mContext;
    private List<WithdraApplyBean> mList=new ArrayList<>();
    private RecordAdapter mAdapter;
    private popRecordListener poplistener;

    public PopRecordModule(Context ctx, List<WithdraApplyBean> mList,popRecordListener l) {
        mContext=ctx;
        this.mList=mList;
        poplistener = l;
        initView();
        mAdapter.addData(mList);
    }

    @Override
    public void setPopwindow(PopupWindow pop) {
        mPopwindows = pop;
    }

    @Override
    public View getView() {
        return mContentView;
    }

    private void initView() {
        mContentView = LayoutInflater.from(mContext).inflate(R.layout.pop_record_module, new LinearLayout(mContext), false);
        setListener();
    }
    private void setListener() {
        View mVwPopBlan=(View)mContentView.findViewById(R.id.vw_pop_blank);
        TextView mTvPopRecordCancel=(TextView)mContentView.findViewById(R.id.tv_pop_record_cancel);
        RecyclerView mRvPopPreferModule=(RecyclerView)mContentView.findViewById(R.id.rv_pop_record_list);
        TextView add_card = (TextView)mContentView.findViewById(R.id.add_card);
        mRvPopPreferModule.setLayoutManager(new LinearLayoutManager(mContext));
        mRvPopPreferModule.setAdapter(mAdapter=new RecordAdapter(mContext));
        //适配器点击事件
        mAdapter.setPreferListItemClickListener(new RecordAdapter.PreferListItemClickListener(){
            @Override
            public void onItemClick(View view, int position) {
                poplistener.PopClickTv(mList.get(position).getRealName(),mList.get(position).getBankName(),mList.get(position).getBankNum());
                mPopwindows.dismiss();
            }
        });
        mVwPopBlan.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                mPopwindows.dismiss();
            }
        });
        mTvPopRecordCancel.setOnClickListener(new NoDoubleClickListener(){
            @Override
            protected void onNoDoubleClick(View v) {
                mPopwindows.dismiss();
            }
        });
        add_card.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                poplistener.addCard();
            }
        });
    }

    public interface popRecordListener {
        void PopClickTv(String readname, String bankname, String banknum);
        void addCard();
    }
}
